import type { ChatRecord } from "@/types";
import axios from "../index";
const prefix = '/api/'
const CHAT_USER_PREFIX = prefix + 'chatUser/'


const chatUserApi = {
    listByName: (userName:string) => {
        return axios.get(CHAT_USER_PREFIX + `listByName?userName=${userName}`)
    },
    getUserInfo: (userName:string) => {
        return axios.get(CHAT_USER_PREFIX + `getByUserName?userName=${userName}`)
    },
    beginNewChat:(relationshipId:string) => {
        return axios.post(CHAT_USER_PREFIX + 'beginNewChat' , {
            relationshipId
        })
    },
    getLatelyChat: () => {
        return axios.get(CHAT_USER_PREFIX + 'getLatelyChat')
    },
    getLatelyChatRecords:() => {
        return axios.get(CHAT_USER_PREFIX + 'getLatelyChatRecords')
    },
    sendMessage: (record:ChatRecord) => {
        return axios.post(CHAT_USER_PREFIX + 'sendMessage',
        record
        )
    },
    checkOnline: (frindName:string) => {
        return axios.get(CHAT_USER_PREFIX + `checkOnline?friendName=${frindName}`)
    },
    videoInvite: (friendName:string) => {
        return axios.post(CHAT_USER_PREFIX + 'videoInvite', {
            friendName
        })
    },
    videoInviteConfirm: (confirm:boolean,friendName:string) => {
        return axios.post(CHAT_USER_PREFIX + 'videoInviteConfirm',{
            confirm,
            friendName
        })
    },
    stopVideo: (friendName:string) => {
        return axios.get(CHAT_USER_PREFIX + `stopVideo?friendName=${friendName}`)
    },
    preHandleIMG: (chatRecord:ChatRecord) => {
        return axios.post(CHAT_USER_PREFIX + 'preHandleIMG',
        chatRecord)
    },
    fetchChatRecords: ( friendShipId:string, current:string, total:string) => {
        return axios.get(CHAT_USER_PREFIX + `fetchChatRecords?friendShipId=${friendShipId}&current=${current}&total=${total}`)
    }
}

export default chatUserApi